<%@ page 
    language="java" 
    import="java.sql.*,javax.sql.DataSource,javax.naming.*,java.io.*" 
    session="true"%>

<%!
    private static final String DEFAULT_DATA_SOURCE_JNDI_NAME = "jdbc/PMSDS";
    String db="pmsdb";

    private Connection getDbConnection(String dsName) throws NamingException,SQLException{
		final Context initCtx = new InitialContext();
		final Context envCtx = (Context)initCtx.lookup("java:comp/env");
		final DataSource ds =	(DataSource)envCtx.lookup(dsName);
		return ds.getConnection();
    } 
    public Connection getAdminConnection()throws SQLException, NamingException,ClassNotFoundException{ 	
  	//comment/uncomment following line if you dont/do want to use DataSource
        return getDbConnection(DEFAULT_DATA_SOURCE_JNDI_NAME);
        
        //comment/uncomment following line if you dont/do want to create connection yourself
        //return getCon();
    }  
	 public Connection getConnection(HttpSession session1)throws SQLException, NamingException,ClassNotFoundException{ 	
  	//comment/uncomment following line if you dont/do want to use DataSource
        return getDbConnection("jdbc/"+session1.getAttribute("db"));
        
        //comment/uncomment following line if you dont/do want to create connection yourself
        //return getCon();
    }  
    public Connection getCon()throws SQLException,ClassNotFoundException { 	
  	///*String db = "rizwan_yq";  
    //String db = "pmsdb";  
  	Class.forName("com.mysql.jdbc.Driver");
	Class.forName("org.gjt.mm.mysql.Driver");
  	String url = "jdbc:mysql://localhost:3307/"+db+"?"+"user=root&password=root";
	Connection c = DriverManager.getConnection(url);
        return c;
        
    }
%>
